package com.zkingsoft.wechat;


import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.web.BaseAction;
import com.zkingsoft.bean.BizActivities;
import com.zkingsoft.bean.BizUser;
import com.zkingsoft.dao.BizCollageInfoDao;
import com.zkingsoft.redis.RedisUserLoginUtils;
import com.zkingsoft.service.BizActivitiesService;
import com.zkingsoft.service.BizCollageService;
import com.zkingsoft.wechat.vo.CollageVo;

/**
 * @description (拼团)
 * @author 何明
 * @date 2018-05-23 00:08
 */
@Controller
@RequestMapping(value = "wxapi/collage")
public class WxCollageAction extends BaseAction{

	@Autowired
	private BizActivitiesService bizActivitiesService;
	@Autowired
	private BizCollageService bizCollageService;
	@Autowired
	RedisUserLoginUtils redisUserLoginUtils;
	@Autowired
	private BizCollageInfoDao collageInfoDao;
	
	
	
	/**
	 * 新增拼团活动
	 */   
   	@RequestMapping(value =  "/addCollageVo")
	public @ResponseBody AjaxResult addCollageVo(@RequestBody CollageVo collageVo) {
   		
   		
   		LogUtil.debug("CollageVo={}", collageVo);
   		
		return null;
		 
	}
   	
   	/**
   	 * 新增拼团活动
   	 */   
   	@RequestMapping(value =  "/addCollage")
   	public @ResponseBody AjaxResult addCollage(@RequestBody BizActivities bizActivities) {
   		BizUser loginUser = redisUserLoginUtils.getLoginUser();
   		LogUtil.info("获取到登录用户={}", loginUser);
   		int i=bizCollageService.addCollage(bizActivities,loginUser);
   		if(i > 0){
   			return new AjaxResult(AjaxResult.STATUS_SUCCESS, "创建拼团成功");
   		}else {
   			return new AjaxResult(AjaxResult.STATUS_FAIL, "创建拼团失败");
   		}
   	}
	
	/**
	 * 修改拼团活动
	 */   
   	@RequestMapping(value =  "/modifyCollage")
	public @ResponseBody AjaxResult modifyCollage(@RequestBody BizActivities bizActivities) {
		BizUser loginUser = redisUserLoginUtils.getLoginUser();
		LogUtil.info("获取到登录用户={}", loginUser);
	 	int i=bizCollageService.modifyCollage(bizActivities,loginUser);
	 	if(i > 0){
	 		return new AjaxResult(AjaxResult.STATUS_SUCCESS, "修改拼团成功");
	 	}else {
	 		return new AjaxResult(AjaxResult.STATUS_FAIL, "修改拼团失败");
		}
	}
	
	/**
	 * 删除拼团活动
	 */   
   	@RequestMapping(value =  "/delCollage")
	public @ResponseBody AjaxResult delCollage(@RequestBody List<String> ids) {
		BizUser loginUser = redisUserLoginUtils.getLoginUser();
		LogUtil.info("获取到登录用户={}", loginUser);
	 	int i=bizCollageService.delCollage(ids,loginUser);
	 	if(i > 0){
	 		return new AjaxResult(AjaxResult.STATUS_SUCCESS, "修改拼团成功");
	 	}else {
	 		return new AjaxResult(AjaxResult.STATUS_FAIL, "修改拼团失败");
		}
	}
   	   
	/**
	 * 查询拼团详情
	 * status ：1 未成团   2 已成团   3 已失效
	 */   
   	@RequestMapping(value =  "/queryDetail/{actId}/{status}")
	public @ResponseBody AjaxResult queryDetail(@PathVariable("actId") String actId,@PathVariable("status") String status) {
   		
   		return new AjaxResult(AjaxResult.STATUS_SUCCESS,collageInfoDao.selectByColId(actId,status));
   	}
	   
	/**
	 * 查询团信息
	 */   
	@RequestMapping(value =  "/queryCinfo/{cinfoId}")
	public @ResponseBody AjaxResult queryCinfo(@PathVariable("cinfoId") String cinfoId) {
		
		return new AjaxResult(AjaxResult.STATUS_SUCCESS,Arrays.asList(collageInfoDao.selectByCinfoId(cinfoId)));
	}
}